import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/manager/xindong_tencent_singleton.dart';
import 'package:xindong/routes/conversation/view/xindong_liaotian_custom_message_container.dart';
import 'package:xindong/routes/conversation/view/xindong_liaotian_message_image_cell.dart';
import 'package:xindong/routes/conversation/view/xindong_liaotian_message_sound_cell.dart';
import 'package:xindong/routes/conversation/view/xindong_liaotian_message_text_cell.dart';
import 'package:xindong/routes/tab_chats/xindong_chat_message_type.dart';
import 'package:xindong/widgets/common/xindong_app_bar.dart';
import 'package:xindong/widgets/xindong_avatar.dart';
import 'package:tencent_cloud_chat_uikit/tencent_cloud_chat_uikit.dart';

class XinDongLiaoTianServiceYeMian extends StatelessWidget {
  const XinDongLiaoTianServiceYeMian({super.key});

  @override
  Widget build(BuildContext context) {
    final chatMessageType = XinDongChatMessageType();
    // 聊天内容最大宽度，32边距 20间距 80头像+错误图标/未读已读
    final maxWidth = screenWidth - 32 - 20 - 80;
    final messageItemBuilder = MessageItemBuilder(
      // 文本
      textMessageItemBuilder: (V2TimMessage message, bool isShowJump, VoidCallback clearJump) {
        return XinDongLiaoTianMessageText(message: message, maxWidth: maxWidth);
      },
      // 语音
      soundMessageItemBuilder: (V2TimMessage message, bool isShowJump, Function() clearJump) {
        return XinDongLiaoTianMessageSound(message: message, maxWidth: maxWidth, clearJump: clearJump);
      },
      // 图片
      imageMessageItemBuilder: (V2TimMessage message, bool isShowJump, Function() clearJump) {
        return XinDongLiaoTianMessageImage(message: message);
      },
      customMessageItemBuilder: (V2TimMessage message, bool isShowJump, Function() clearJump) {
        return XinDongLiaoTianCustomMessageContainer(
          message: message,
          maxWidth: maxWidth,
          chatMessageType: chatMessageType,
          clearJump: clearJump, userClass: null,
        );
      },
    );
    return TIMUIKitChat(
      conversation: V2TimConversation(
        conversationID: 'c2c_${XinDongTencentSingleton.instance.customerID}',
        type: ConversationType.V2TIM_C2C,
        showName: "官方客服",
        userID: XinDongTencentSingleton.instance.customerID,
        groupID: null,
      ),
      appBarConfig: XinDongAppBar("与客服的聊天"),
      messageItemBuilder: messageItemBuilder,
      morePanelConfig: MorePanelConfig(showFilePickAction: false),
      config: const TIMUIKitChatConfig(isAllowLongPressMessage: false, isAllowEmojiPanel: false),
      userAvatarBuilder: userAvatarBuilder,
    );
  }

  // 头像
  Widget userAvatarBuilder(BuildContext context, V2TimMessage message) {
    return XinDongAvatar(url: message.faceUrl, size: 40);
  }
}
